from django.db import models
from django.contrib.auth.models import User


class Network(models.Model):
    code = models.CharField(max_length=10, unique=True, verbose_name='台网代码')
    name = models.CharField(max_length=30, blank=True, verbose_name='台网名称')
    remark = models.TextField(max_length=1000, blank=True, verbose_name='备注')

    class Meta:
        verbose_name = '台网信息'
        verbose_name_plural = '台网信息'

    def __str__(self):
        return self.code

    def get_absolute_url(self):
        '''
        Todo
        :return:
        '''
        pass


class Station(models.Model):
    code = models.CharField(max_length=10, unique=True, verbose_name='台站代码')
    name = models.CharField(max_length=30, blank=True, verbose_name='台站名称')
    network = models.ForeignKey('Network', on_delete=models.CASCADE, related_name='stations', verbose_name='所属台网')
    longitude = models.FloatField(default=0.0, verbose_name='台站经度')
    latitude = models.FloatField(default=0.0, verbose_name='台站纬度')
    altitude = models.FloatField(default=0.0, verbose_name='台站高程')
    remark = models.TextField(max_length=1000, blank=True, verbose_name='备注')

    class Meta:
        verbose_name = '台站信息'
        verbose_name_plural = '台站信息'

    def __str__(self):
        return '{network}/{station}'.format(network=self.network.code, station=self.code)


class Personnel(models.Model):
    name = models.CharField(max_length=32, verbose_name='名字')
    belong = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='所属台站')

    class Meta:
        verbose_name = '员工信息'
        verbose_name_plural = '员工信息'

    def __str__(self):
        return self.name


